package com.gotrade.ftpdemo.model;

import lombok.*;

import javax.validation.constraints.NotBlank;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;

/**
 * @Author jason.tang
 * @Date 2019/03/8 06:53
 * @Desc
 */
@Data
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class FileInfo implements Serializable {
    // ftp文件名
    private String fileName;

    // ftp目录
    private String remoteDir;

    // 本地上传文件
    private File localFile;

    public String getRemoteDir() {
        if (this.remoteDir == null) {
            return "";
        }
        return this.remoteDir;
    }

    public File getLocalFile() {
        if (this.localFile == null) {
            try {
                if (this.fileName == null) {
                    throw new Exception("File name cannot empty!");
                }
                String[] temp = this.fileName.split("\\.");
                return File.createTempFile(temp[0], temp[1]);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return this.localFile;
    }
}
